package com.ruoyi.main.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.main.domain.MainSuppier;
import com.ruoyi.main.service.IMainSuppierService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 供应商管理Controller
 * 
 * @author chao
 * @date 2024-07-23
 */
@Controller
@RequestMapping("/main/suppier")
public class MainSuppierController extends BaseController
{
    private String prefix = "main/suppier";

    @Autowired
    private IMainSuppierService mainSuppierService;

    @RequiresPermissions("main:suppier:view")
    @GetMapping()
    public String suppier()
    {
        return prefix + "/suppier";
    }

    /**
     * 查询供应商管理列表
     */
    @RequiresPermissions("main:suppier:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(MainSuppier mainSuppier)
    {
        startPage();
        List<MainSuppier> list = mainSuppierService.selectMainSuppierList(mainSuppier);
        return getDataTable(list);
    }

    /**
     * 导出供应商管理列表
     */
    @RequiresPermissions("main:suppier:export")
    @Log(title = "供应商管理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(MainSuppier mainSuppier)
    {
        List<MainSuppier> list = mainSuppierService.selectMainSuppierList(mainSuppier);
        ExcelUtil<MainSuppier> util = new ExcelUtil<MainSuppier>(MainSuppier.class);
        return util.exportExcel(list, "供应商管理数据");
    }

    /**
     * 新增供应商管理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存供应商管理
     */
    @RequiresPermissions("main:suppier:add")
    @Log(title = "供应商管理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(MainSuppier mainSuppier)
    {
        return toAjax(mainSuppierService.insertMainSuppier(mainSuppier));
    }

    /**
     * 修改供应商管理
     */
    @RequiresPermissions("main:suppier:edit")
    @GetMapping("/edit/{id}")
    public String edit(@PathVariable("id") Long id, ModelMap mmap)
    {
        MainSuppier mainSuppier = mainSuppierService.selectMainSuppierById(id);
        mmap.put("mainSuppier", mainSuppier);
        return prefix + "/edit";
    }

    /**
     * 修改保存供应商管理
     */
    @RequiresPermissions("main:suppier:edit")
    @Log(title = "供应商管理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(MainSuppier mainSuppier)
    {
        return toAjax(mainSuppierService.updateMainSuppier(mainSuppier));
    }

    /**
     * 删除供应商管理
     */
    @RequiresPermissions("main:suppier:remove")
    @Log(title = "供应商管理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(mainSuppierService.deleteMainSuppierByIds(ids));
    }
}
